package Test_0814.ioperations;

import Test_0814.book.Book;
import Test_0814.book.BookShelf;

import java.util.Scanner;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 * Dare: 2024-08-15
 * Time: 9:34
 */
public class FindOperation implements IoPeration{
    public void work(BookShelf bookshelf){
        System.out.println("查找图书");
        System.out.println("请输入你要查找的书");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        int ret=bookshelf.getUseSize();
        for (int i = 0; i < ret; i++) {
            Book book=bookshelf.getBook(i);
            //如果有相对应的名字，打印出这本书的相关信息
            //这个是引用类型，要用equals来进行比较，不能写成book==name
            if(book.getBookName().equals(name)){
                System.out.println("找到了！！！");
                System.out.println(book);
                return;//结束该流程
            }
        }
        //如果没有找到，打印
        System.out.println("很遗憾，没有这本书");
    }
}
